/* eslint-disable no-undef */
import type { ConsultType } from '@/enums'
import type { PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
export const useConsultStore = defineStore(
  'consult',
  () => {
    const consult = ref<PartialConsult>({})
    // 设置问诊类型
    const setConsultType = (type: ConsultType) => {
      consult.value.type = type
    }
    // 设置问诊医院类别
    const setConsultIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }
    // 设置问诊的科室id
    const setConsultDepId = (id: string) => {
      consult.value.depId = id
    }
    // 设置问诊的详情信息
    const setInfo = (obj: PartialConsult) => {
      const { illnessDesc, illnessTime, consultFlag, pictures } = obj
      consult.value.illnessDesc = illnessDesc
      consult.value.illnessTime = illnessTime
      consult.value.consultFlag = consultFlag
      consult.value.pictures = pictures
    }
    // 设置患者id的方法
    const setPatientId = (id: string) => {
      consult.value.patientId = id
    }
    // 设置优惠券id
    const setCouponId = (id: string) => {
      consult.value.couponId = id
    }

    // 清除consult数据
    const clear = () => {
      consult.value = {}
    }
    return {
      consult,
      setConsultType,
      setConsultIllnessType,
      setConsultDepId,
      setInfo,
      setPatientId,
      setCouponId,
      clear
    }
  },
  { persist: true }
)
